package com.lyw.service;

import com.lyw.dao.HouseDao;
import com.lyw.pojo.House;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class HouseService {
    @Autowired
    private HouseDao houseDao;


    public List<House> listHouse() {
        return houseDao.findAll();
    }

    public Page<Map<String, Object>> findList(String name, Integer pageSize, Integer pageNum) {
        return houseDao.findList('%'+name+'%', PageRequest.of(pageSize,pageNum-1));
    }

    public void delId(Long id) {
        houseDao.deleteById(id);
    }

    public void addHouse(House house) {
        houseDao.save(house);
    }

    public House findId(Long id) {
        return houseDao.findById(id).get();
    }

    public void updHouse(House house) {
        houseDao.saveAndFlush(house);
    }

    public List<House> mai( ) {
        return houseDao.mai();
    }

    public List<House> zu() {
        return houseDao.zu();
    }

    public List<House> two() {
        return houseDao.two();
    }
}
